import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'

import configRoutes from './modules'
import sharedRoutes from './modules/shared'

export const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    name: 'Layout',
    component: () => import('@/components/Layout/index.vue'),
    meta: {
      title: '首页',
    },
    children: [...configRoutes],
  },
  ...sharedRoutes,
]

const router = createRouter({
  history: createWebHistory(),
  routes,
})

router.beforeEach((to, from, next) => {
  if(to.meta.title) (document as any).title = to.meta.title
  next()
})

export default router
